package com.yuhuihui.common.utils.excel.export;

import com.yuhuihui.common.utils.excel.export.parameters.ExcelExportSheetParameter;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 导出工作表可运行
 *
 * @author yuhh
 * @date 2022-08-22 16:44:41
 * @see Runnable
 */
public class ExportSheetRunnable<T> implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(ExportSheetRunnable.class);

    /**
     * excel工作区间
     */
    private Workbook workBook;

    /**
     * sheet参数
     */
    private ExcelExportSheetParameter<T> parameter;

    public ExportSheetRunnable(Workbook workBook, ExcelExportSheetParameter<T> parameter){
        this.workBook = workBook;
        this.parameter = parameter;
    }

    private ExportSheetRunnable(){

    }

    @Override
    public void run() {
        try {
            ExcelExport.creatSheet(workBook, parameter, true);
        } catch (Exception e){
            logger.error("多线程导出excel出现异常", e);
        }
    }


    public Workbook getWorkBook() {
        return workBook;
    }

    public void setWorkBook(Workbook workBook) {
        this.workBook = workBook;
    }

    public ExcelExportSheetParameter<T> getParameter() {
        return parameter;
    }

    public void setParameter(ExcelExportSheetParameter<T> parameter) {
        this.parameter = parameter;
    }
}
